﻿using System;
using System.Net.Sockets;
using System.Windows.Forms;
using Minecraft.Model;
using Minecraft.Model.ReqResp;
using TestClient.Client.Com;
using TestClient.Client.Send;
using TestClient.Util;

namespace TestClient
{
    public partial class MainForm : Form
    {
        /// <summary>
        /// 客户端维护的一个连接
        /// </summary>
        public static Socket ClientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

        public MainForm()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void loginBtn_Click(object sender, EventArgs e)
        {
            LoginForm.CreateForm().Show();
        }


        /// <summary>
        /// 一打开主窗体，就开始建立连接
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MainForm_Load(object sender, EventArgs e)
        {
            //1.一打开主窗体，就开始建立连接
            ClientStart.Start();
        }


		/// <summary>
		/// 
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
        private void getAllAchievementbutton_Click(object sender, EventArgs e)
        {
            EnumCommand command = EnumCommand.Achievements_AchievementsSelectAll;

            var resp = new BaseResp();

            RespLevelJudge.Do(command, resp, () =>
            {
                //登录成功
                ComManager.Send(ClientSocket, () =>
                {
                    return AchievementsSelectAll.GetReq();
                });
            });
        }


        /*
         *
         *根据playerId查此用户的成就信息
         */
        private void getAchievementById_button_Click(object sender, EventArgs e)
        {
	        EnumCommand command = EnumCommand.Achievements_AchievementsSelectById;

	        var resp = new BaseResp();

	        RespLevelJudge.Do(command, resp, () =>
	        {
		        //登录成功
		        ComManager.Send(ClientSocket, () =>
		        {
			        return AchievementsSelectById.GetReq();
		        });
	        });
		}



	    /// <summary>
	    /// 特定用户领奖
	    /// </summary>
	    /// <param name="sender"></param>
	    /// <param name="e"></param>
	    private void receivePrice_button_Click(object sender, EventArgs e)
	    {
		    EnumCommand command = EnumCommand.Achievements_AchievementsReceiveAward;

		    var resp = new BaseResp();

		    RespLevelJudge.Do(command, resp, () =>
		    {
			    //登录成功
			    ComManager.Send(ClientSocket, () =>
			    {
				    return AchievementsReceiveAward.GetReq();
			    });
		    });
	    }


		/// <summary>
		/// 
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void updateAchievement_button_Click(object sender, EventArgs e)
		{
			EnumCommand command = EnumCommand.Achievements_AchievementsReceiveAward;

			var resp = new BaseResp();

			RespLevelJudge.Do(command, resp, () =>
			{
				//登录成功
				ComManager.Send(ClientSocket, () =>
				{
					return AchievementsReceiveAward.GetReq();
				});
			});
		}
	}
}
